//package com.xuzm.netty.config;
//
//import cn.hutool.core.map.BiMap;
//import com.xuzm.netty.dto.RunDataDto;
//import com.xuzm.netty.dto.ServerHandlerConsumer;
//import com.xuzm.netty.operator.ServerHandlerOperator;
//import com.xuzm.netty.server.NettyServer;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.ApplicationArguments;
//import org.springframework.boot.ApplicationRunner;
//import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
//import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
//import org.springframework.scheduling.support.CronTrigger;
//import org.springframework.stereotype.Component;
//
//import java.util.Objects;
//import java.util.concurrent.CountDownLatch;
//import java.util.concurrent.atomic.AtomicBoolean;
//
//@Slf4j
////@Component
//public class NettyServerRun implements ApplicationRunner {
//    @Value("${server.netty.port}")
//    private int port;
//    @Autowired
//    private ServerHandlerConsumer consumer;
//    @Autowired
//    private ThreadPoolTaskScheduler taskScheduler;
//    @Autowired
//    private ThreadPoolTaskExecutor executor;
//    @Override
//    public void run(ApplicationArguments args) throws Exception {
//        AtomicBoolean enableNettyServer = new AtomicBoolean(false);
//        executor.submit(()-> startServer( enableNettyServer));
//        if(!enableNettyServer.get()){
//            // netty服务启动失败
//            throw new RuntimeException("netty服务启动失败请检查端口等信息是否可用");
//        }
//        // 59 59 23 ? * ?  每天最后一秒运行的cron表达式
//        taskScheduler.schedule(this::exec, triggerContext -> new CronTrigger("0/30 * * * * ?").nextExecutionTime(triggerContext));
//    }
//
//    private void exec() {
//    }
//
//    /**
//     * 启动netty服务器
//     * @param downLatch 等待线程
//     * @param enableNettyServer true=启动成功 false=启动失败
//     */
//    private void startServer(AtomicBoolean enableNettyServer) {
//        try {
//            log.info("开始启动netty服务器，端口{}", 8099);
//            // TODO: 2024/7/16 netty服务启动失败后的重启
//            new NettyServer(8099, consumer).start();
//
//            log.info("启动netty服务器成功！");
//        } catch (Exception e) {
//            e.printStackTrace();
//            enableNettyServer.set(false);
//        }
//    }
//}
